package com.example.sunmiv1.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.sunmiv1.R;
import com.example.sunmiv1.entity.GoodBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class CollectingSilverClassificationAdapter extends BaseAdapter {

    private Context context;
    private List<GoodBean.DataBean> list;
    ViewHolder viewHolder;
    private int isSelect = 0;

    public CollectingSilverClassificationAdapter(Context context, List<GoodBean.DataBean> list) {
        this.context = context;
        this.list = list;
    }

    public void setSelect(int isSelect) {
        this.isSelect = isSelect;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.collecting_silver_classification_adapter, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        if (isSelect == position) {
            convertView.setBackgroundResource(R.color.white);
            viewHolder.collectingSilverClassificationAdapterTv.setTextColor(context.getResources().getColor(R.color.login_textColor1));
            viewHolder.collectingSilverClassificationAdapterView.setVisibility(View.VISIBLE);
        }else{
            convertView.setBackgroundResource(R.color.collectingSilver_classificationBg);
            viewHolder.collectingSilverClassificationAdapterTv.setTextColor(context.getResources().getColor(R.color.login_textColor2));
            viewHolder.collectingSilverClassificationAdapterView.setVisibility(View.INVISIBLE);
        }
        viewHolder.collectingSilverClassificationAdapterTv.setText(list.get(position).getClass_name());
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.collectingSilver_classification_adapter_view)
        View collectingSilverClassificationAdapterView;
        @BindView(R.id.collectingSilver_classification_adapter_tv)
        TextView collectingSilverClassificationAdapterTv;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
